/*
Copyright 2021 LuJun

Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is furnished 
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in 
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/// <reference path="../cocos/event/event-target.ts" />

/**
 * @zh
 * LCC服务器框架依赖NPM包:<br/>
 * mysql url express cors http https request
 */
namespace lcc {

const { isMainThread } = require('worker_threads');

/**
 * @zh
 * 版本号
 */
export const VERSION = '1.0.0';

/**
 * @zh
 * 调试用宏定义
 */
export namespace DEBUG {

    /**
     * @zh
     * 定时器模块
     */
    export let TIMER = false;

    /**
     * @zh
     * 网络模块
     */
    export let NETWORK = false;

    /**
     * @zh
     * 配置模块
     */
    export let CONFIG = false;

    /**
     * @zh
     * 数据表模块
     */
	export let TABLE = false;
	
    /**
     * @zh
     * 数据库模块
     */
    export let DATABASE = false;

    /**
     * @zh
     * Redis模块
     */
    export let REDIS = false;

    /**
     * @zh
     * 工作者模块
     */
    export let WORKER = false;
}

/**
 * @zh
 * 启动时间
 */
export const BOOT_TIME = Date.now();

/**
 * @zh
 * 事件类
 */
class EventTarget extends cocos.event.EventTarget {}

/**
 * @zh
 * 事件中心
 */
export const EventCenter = new EventTarget();

/**
 * @zh
 * LCC事件
 */
export namespace Events {
	/**
	 * @zh
	 * 发送给父程序消息
	 */
	export const TO_PARENT = "toParent";

	/**
	 * @zh
	 * 从父程序接收消息
	 */
	export const FROM_PARENT = "fromParent";
}

/**
 * @zh
 * 工作线程
 */
export const IS_WORKER_THREAD = !isMainThread;

/**
 * @zh
 * 工作进程
 */
export const IS_WORKER_PROCESS = process.env.isWorker == 'true';

/**
 * @zh
 * 主进程并且是主线程
 */
export const IS_MASTER = !IS_WORKER_PROCESS && !IS_WORKER_THREAD;

/**
 * @zh
 * 当前的工作组
 */
export let __WORKER_GROUP:string;

//console.log('lcc', `IS_MASTER:${IS_MASTER},IS_WORKER_THREAD:${IS_WORKER_THREAD},IS_WORKER_PROCESS:${IS_WORKER_PROCESS},PROCESS_ID:${PROCESS_ID},THREAD_ID:${THREAD_ID}`);

}

// 全局挂载
globalThis.lcc = lcc;
